function MyAjax(options) {
    const defaults = {
        type: "get",
        url: "",
        data: {},
        header: { "Content-Type": "application/x-www-form-urlencoded" },
        success: function() {},
        error: function() {},
    };
    Object.assign(defaults, options);
    const xhr = new XMLHttpRequest();
    const arr = [];
    for (let k in options.data) arr.push(`${k}=${options.data[k]}`);
    let str = arr.join("&");
    if (defaults.type === "get" || defaults.type === "GET") {
        defaults.url = `${defaults.url}?${str}`;
    }
    xhr.open(defaults.type, defaults.url);
    if (defaults.type === "post" || defaults.type === "POST") {
        let contentType = defaults.header["Content-Type"];
        xhr.setRequestHeader("Content-Type", contentType);
        contentType === "application/json" ?
            xhr.send(JSON.stringify(defaults.data)) :
            xhr.send(str);
    } else {
        xhr.send();
    }
    xhr.onload = function() {
        let contentType = xhr.getResponseHeader("Content-Type");
        let responseText = xhr.responseText;
        if (contentType.includes("application/json")) {
            responseText = JSON.parse(responseText);
        }
        if (xhr.status == 200) {
            defaults.success(responseText, xhr);
        } else {
            defaults.error(responseText, xhr);
        }
    };
}